<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="${APP_PATH}/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>教学管理系统</title>
    <link rel="icon" href="public/favicon.ico" type="image/ico">
    <%@include file="/commons.jsp" %>
    <!--日期选择插件-->
    <script src="public/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="public/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <%@ include file="/menu.jsp" %>
        <!--End 左侧导航-->
        <!--头部信息-->
        <%@ include file="/head.jsp" %>
        <!--End 头部信息-->
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <form class="pull-right search-bar" id="search" method="post" action="/manage/user/indexDo">
                                    <div class="input-group">
                                        <div class="input-group-btn">
                                            <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                                                角色 <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu" id="role">
                                                <li><a href="javascript:void(0)" data-field="cat_name">角色</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">学生</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">班主任</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">教师</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">就业专员</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">公司</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">教学主管</a></li>
                                                <li><a href="javascript:void(0)" data-field="cat_name">管理员</a></li>
                                            </ul>
                                        </div>
                                        <input type="text" class="form-control" name="condition" placeholder="请输入查询条件"/>
                                        <div class="input-group-btn">
                                            <button class="btn btn-default dropdown-toggle" id="searchBtn" type="button">搜索</button>
                                        </div>
                                    </div>
                                </form>
                                <div class="input-group-btn">
                                    <div class="input-daterange input-group js-datepicker" data-auto-close="false" data-format="YYYY-MM-DD">
                                        <input class="form-control" type="text" id="example-daterange1" name="example-daterange1" placeholder="起始时间">
                                        <span class="input-group-addon"><i class="mdi mdi-chevron-right"></i></span>
                                        <input class="form-control" type="text" id="example-daterange2" name="example-daterange2" placeholder="结束时间">
                                    </div>
                                </div>
                                <div class="input-group-btn">
                                    <a class="btn btn-primary m-r-5" onclick="exportFile()"><i class="mdi mdi-plus"></i>导出</a>
                                </div>
                            </div>
                            <div class="card-body">
                                <form id="dataForm">
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>操作用户</th>
                                                <th>操作详情</th>
                                                <th>操作时间</th>
                                            </tr>
                                            </thead>
                                            <tbody id="dataList">
                                            </tbody>
                                        </table>
                                        <div align="center">
                                            <ul class="pagination" id="pages"></ul>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<script type="text/javascript">
    $(function () {
        layer.msg("加载中", {time: 200, icon: 16, shift: 5}, function () {
            goPage(1);
        });//layer
        // 下拉事件
        $('.search-bar .dropdown-menu a').click(function () {
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });
    });//入口

    function goPage(pageNum) {
        let rnamVal = $('#search-btn').text().trim();
        $.ajax({
            url: "manage/log/indexDo?pageNum=" + pageNum + "&rname=" + rnamVal,
            type: "post",
            data: $("#search").serialize(),
            dataType: "json",
            success: function (obj) {
                if (obj.result) {
                    let dataHtml = template("dataTpl", {
                        logs: obj.logformList
                    });
                    $("#dataList").html(dataHtml);
                    let prePage = obj.pageInfo.pageNum == 1 ? 1 : obj.pageInfo.pageNum - 1;
                    let nextPage = obj.pageInfo.pageNum == obj.pageInfo.pages ? obj.pageInfo.pages : obj.pageInfo.pageNum + 1;
                    var pageMessage = "";
                    pageMessage += '<li class="' + (obj.pageInfo.pageNum == 1 ? "disabled" : "") + '"><a onclick="goPage(' + prePage + ')"><<</a></li>';
                    for (var i = 1; i <= obj.pageInfo.pages; i++) {
                        pageMessage += '<li class="' + (obj.pageInfo.pageNum == i ? "active" : "") + '"><a onclick="goPage(' + i + ')">' + i + ' <span class="sr-only">(current)</span></a></li>';
                    }
                    pageMessage += '<li class="' + (obj.pageInfo.pageNum == obj.pageInfo.pages ? "disabled" : "") + '"><a onclick="goPage(' + nextPage + ')">>></a></li>';
                    $("#pages").html(pageMessage);
                    $("#searchBtn").unbind();
                    $("#searchBtn").click(function () {
                        goPage(obj.pageInfo.pageNum);
                    })
                }
            }//success
        });//ajax
    }

    function exportFile() {

    }

</script>
</body>
</html>
<script id="dataTpl" type="text/html">
    {{each logs log index}}
    <tr>
        <td>{{index+1}}</td>
        <td>{{log.user.uname}}</td>
        <td>{{log.info}}</td>
        <td>{{log.dotime}}</td>
    </tr>
    {{/each}}
</script>
